from django.db import models
#对数据库进行操作
# Create your models here.


gender_choices=(
    (1,"男"),
    (2,"女"),
)
class UserInfo(models.Model):
    name = models.CharField(max_length=32,verbose_name="姓名")
    password = models.CharField(max_length=64)
    age = models.IntegerField(default=2)  #默认值2
    size = models.DecimalField(null=True,blank=True,max_digits=10,decimal_places=2) #可以为空
    #总长度10为,小数点后最多2位
    depart_id=models.BigIntegerField(verbose_name="部门1")
    depart_id2=models.ForeignKey(to="Department",to_field="id",on_delete=models.SET_NULL,null=True,blank=True,)
    gender = models.SmallIntegerField(choices=gender_choices)

    # def __unicode__(self):
    #     return '%s' % (self.name)
    #
    # def toJSON(self):
    #     import json
    #     return json.dumps(dict([(attr, getattr(self, attr)) for attr in [f.name for f in self._meta.fields]]))


class Department(models.Model):
    title = models.CharField(max_length=16)

# class Role(models.Model):
#     caption = models.CharField(max_length=16)
